//#include <iostream>
#include <mpi.h>
#include <stdio.h>

#include "data.h"
#include "psUtil.h"
#include "psSearch.h"

using namespace std;

int nInds, nSteps;

int main(int argc, char *argv[]) {
	ArgStruct args = PSUtil::getArgs(argc, argv); // Commandline arguments
	MPI::Init(argc, argv);

	int size = MPI::COMM_WORLD.Get_size();
	int rank = MPI::COMM_WORLD.Get_rank();


	Data dataObj(args.dataFileName);

	dataObj.setDimensions(nInds, nSteps);
	vector<charVec> data = dataObj.getData();

	vector<int> grpCountVector = dataObj.getGrpCountVector();
	int grpCount = dataObj.getGrpCount(grpCountVector);	

	PSSearch s(dataObj, args, size, rank);

	vector<intIntVec> allColor;
	if (rank == 0) allColor =  s.genAllColoring(); // All Color Assignments


	if (rank == 0) {
		double elapsedTime = s.partitionSendReceive(allColor, size);
		cout << "Time elapsed: " << elapsedTime << endl;
	}
	else {
		s.calcAndSend(rank);
	}

	MPI_Finalize();
	return 0;
}
